<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller {
    public function News(){
        $model = M('news');
        $count = $model -> count();
        //分页第二部：实例化分页类，传递参数
        $page = new \Think\Page($count,4);  //每页显示一个
        //分页第三步（可选）定制分页按钮的提示文字
        $page -> rollPage = 3;             //大于3条信息就显示首页和末页
        $page -> lastSuffix = false;       //末页是否显示数字
        $page -> setConfig('prev','上一页');
        $page -> setConfig('next','下一页');
        $page -> setConfig('first','首页');
        $page -> setConfig('last','末页');
        //分页第四步：使用show方法生成url
        $show = $page -> show();
        //分页第五步：使用limit方法展示数据
        $data = $model -> limit($page->firstRow,$page->listRows) -> order('time desc') -> select();
        $this -> assign('data',$data);
        $this -> assign('show',$show);
        $this -> display();
    }
    public function newsshow(){
        $id=I('get.id');
        $newshow = M('news')->find($id);
        $newshow['text'] = html_entity_decode($newshow['text']);
        $prev= M('news')->find($id-1);
        $next= M('news')->find($id+1);
        if(empty($prev)){$prev['title']="没有了";}
        if(empty($next)){$next['title']="没有了";}
        $this -> assign('newshow',$newshow);
        
        $this -> assign('prev',$prev);
        $this -> assign('next',$next);
        $data_xg = M('tuijian') -> where('id!='.$id) -> limit(4) -> select();
        $this->assign('data_xg',$data_xg);
        $this -> display();
    }
}